package com.chainshop.expenseRequest.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.chainshop.common.core.domain.pojo.ExpenseRequests;
import com.chainshop.expenditure.service.IExpenseRecordsService;
import com.chainshop.expenseRequest.service.IExpenseRequestsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chainshop.common.annotation.Log;
import com.chainshop.common.core.controller.BaseController;
import com.chainshop.common.core.domain.AjaxResult;
import com.chainshop.common.enums.BusinessType;

import com.chainshop.common.utils.poi.ExcelUtil;
import com.chainshop.common.core.page.TableDataInfo;

/**
 * 存储支出申请的Controller
 * 
 * @author hmy
 * @date 2024-08-15
 */
@RestController
@RequestMapping("/money/expenseRequest")
public class ExpenseRequestsController extends BaseController
{
    @Autowired
    private IExpenseRequestsService expenseRequestsService;
    @Autowired
    private IExpenseRecordsService expenseRecords;
    @PutMapping("/pass/{id}")
    public AjaxResult pass(@PathVariable Long id)
    {
        ExpenseRequests expenseRequests = new ExpenseRequests();
        expenseRequests.setId(id);
        expenseRequests.setAuditStatus(2);
        int i = expenseRequestsService.updateExpenseRequests(expenseRequests);
        ExpenseRequests expenseRequests1 = expenseRequestsService.selectExpenseRequestsById(id);
        expenseRecords.insertByExpenseRequest(expenseRequests1);
        return toAjax(i);
    }
    @PutMapping("/reject/{id}")
    public AjaxResult reject(@PathVariable Long id)
    {
        ExpenseRequests expenseRequests = new ExpenseRequests();
        expenseRequests.setId(id);
        expenseRequests.setAuditStatus(3);
        return toAjax(expenseRequestsService.updateExpenseRequests(expenseRequests));
    }


    /**
     * 查询存储支出申请的列表
     */
    @PreAuthorize("@ss.hasPermi('money:expenseRequest:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExpenseRequests expenseRequests)
    {
        startPage();
        List<ExpenseRequests> list = expenseRequestsService.selectExpenseRequestsList(expenseRequests);
        return getDataTable(list);
    }

    /**
     * 导出存储支出申请的列表
     */
    @PreAuthorize("@ss.hasPermi('money:expenseRequest:export')")
    @Log(title = "存储支出申请的", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExpenseRequests expenseRequests)
    {
        List<ExpenseRequests> list = expenseRequestsService.selectExpenseRequestsList(expenseRequests);
        ExcelUtil<ExpenseRequests> util = new ExcelUtil<ExpenseRequests>(ExpenseRequests.class);
        util.exportExcel(response, list, "存储支出申请的数据");
    }

    /**
     * 获取存储支出申请的详细信息
     */
    @PreAuthorize("@ss.hasPermi('money:expenseRequest:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(expenseRequestsService.selectExpenseRequestsById(id));
    }

    /**
     * 新增存储支出申请的
     */
    @PreAuthorize("@ss.hasPermi('money:expenseRequest:add')")
    @Log(title = "存储支出申请的", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExpenseRequests expenseRequests)
    {
        return toAjax(expenseRequestsService.insertExpenseRequests(expenseRequests));
    }

    /**
     * 修改存储支出申请的
     */
    @PreAuthorize("@ss.hasPermi('money:expenseRequest:edit')")
    @Log(title = "存储支出申请的", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExpenseRequests expenseRequests)
    {
        return toAjax(expenseRequestsService.updateExpenseRequests(expenseRequests));
    }

    /**
     * 删除存储支出申请的
     */
    @PreAuthorize("@ss.hasPermi('money:expenseRequest:remove')")
    @Log(title = "存储支出申请的", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(expenseRequestsService.deleteExpenseRequestsByIds(ids));
    }
}
